class TableRow {
  constructor() {
    this.row = new Array();
    this.push = function(col) {
      let colOpt = col.getColOptions();
      this.row.push(colOpt);
    };
    this._cols = function() {
      return this.row;
    };
  }
}

class TableColumns {
  constructor() {
    this.columnOptions = new Object();
    this.getColOptions = function() {
      return this.columnOptions;
    };
    this._data = function(data) {
      this.columnOptions.IndexID = data;
      this.columnOptions.IndexName = data;
      return this;
    };
    this._title = function(title) {
      this.columnOptions.IndexText = title;
      return this;
    };
    this._width = function(width) {
      this.columnOptions.Width = width;
      return this;
    };
    this._fixed = function(place) {
      this.columnOptions.fixed = place;
      return this;
    };
    this._editable = function(isEditable) {
      this.columnOptions.editable = isEditable;
      return this;
    };
    this._editType = function(type = "input") {
      let editTypes = ["poupSelect","ElInput", "ElInputNumber", "ElSelect", "ElDatePicker", "ElTimeSelect", "ElCascader", "ElSwitch", "ElRate"];
      if (this.columnOptions.editable) {
        let editOpt = new Object();
        if (type === "input") {
          editOpt["name"] = "ElInput";
          this.columnOptions.editRender = editOpt;
        } else if (type === "poupSelect") {
          editOpt["name"] = "poupSelect";
          this.columnOptions.editRender = editOpt;
        } else if (type === "select") {
          editOpt["name"] = "ElSelect";
          this.columnOptions.editRender = editOpt;
        } else if (type === "datePicker") {
          editOpt["name"] = "ElDatePicker";
          this.columnOptions.editRender = editOpt;
        } else if (editTypes.includes(type)) {
          editOpt["name"] = type;
          this.columnOptions.editRender = editOpt;
        } else {
          alert("请正确填写编辑类型参数！");
        }
      }
      return this;
    };
    this._dataSource = function(option) {
      if (this.columnOptions.editable) {
        try {
          Object.assign(this.columnOptions.editRender, option);
        } catch (err) {
          alert("请先调用方法 _editType(<String>) 设置编辑类型!");
        }
      }
      return this;
    };
    this._others = function(optionObj) {
      Object.assign(this.columnOptions, optionObj);
      return this;
    };
  }
}

export { TableRow, TableColumns };
